<template>
  <div class="app-container">
    <!-- <son-comp :fn="fn" :money="1000" /> -->
    <upload-excel :on-success="handleSuccess" :before-upload="beforeUpload" />
    <el-table :data="tableData" border highlight-current-row style="width: 100%;margin-top:20px;">
      <!-- v-for --of--  遍历数组直接拿值 -->
      <el-table-column v-for="item of tableHeader" :key="item" :prop="item" :label="item" />
    </el-table>
  </div>
</template>

<script>
// import sonComp from './components/son-comp.vue'
// import UploadExcelComponent from '@/components/UploadExcel/index.vue'

export default {
  // components: { sonComp },
  // name: 'UploadExcel',
  // components: { UploadExcelComponent },
  data() {
    return {
      tableData: [],
      tableHeader: []
    }
  },
  methods: {
    fn({ results, data }) {
      console.log(results, data)
    },
    beforeUpload(file) {
      // 判断文件大小是否大于1M
      const isLt1M = file.size / 1024 / 1024 < 1
      // 1M = 1024kb = 1024*1024b
      if (isLt1M) {
        return true
      }

      this.$message.warning('请上传小于1M的文件')
      return false
    },
    // 上传成功时处理 results - 表格里内容结果 header 表头
    handleSuccess({ results, header }) {
      console.log(results, header)
      this.tableData = results
      this.tableHeader = header
    }
  }
}
</script>
